package com.yss.reportworld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yss.common.core.utils.StringUtils;
import com.yss.common.core.utils.easyexecl.EasyExeclUtil;
import com.yss.common.core.utils.uuid.IdUtils;
import com.yss.reportworld.domain.DemandBugInfo;
import com.yss.reportworld.service.IDemandBugInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yss.common.logger.annotation.Log;
import com.yss.common.logger.enums.BusinessType;
import com.yss.common.security.annotation.RequiresPermissions;
import com.yss.reportworld.domain.DataDemandBug;
import com.yss.reportworld.service.IDataDemandBugService;
import com.yss.common.core.web.controller.BaseController;
import com.yss.common.core.web.domain.AjaxResult;
import com.yss.common.core.web.page.TableDataInfo;

/**
 * 数据和需求BUG关联关系Controller
 *
 * @author yss
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/datademandbug")
public class DataDemandBugController extends BaseController {
    @Autowired
    private IDataDemandBugService dataDemandBugService;
    @Autowired
    private IDemandBugInfoService demandBugInfoService;

    /**
     * 查询数据和需求BUG关联关系列表
     */
    @RequiresPermissions("reportworld:datademandbug:list")
    @GetMapping("/list")
    public TableDataInfo list(DataDemandBug dataDemandBug) {
        startPage();
        List<DemandBugInfo> list = dataDemandBugService.selectDataDemandBugList(dataDemandBug);
        return getDataTable(list);
    }

    /**
     * 初始化 加载
     */
    @RequiresPermissions("reportworld:datademandbug:list")
    @Log(title = "SQL脚本管理", businessType = BusinessType.OTHER)
    @PostMapping("/init")
    public AjaxResult init(@RequestBody DataDemandBug dataDemandBug) {
        AjaxResult ajax = AjaxResult.success();
        // 当前版本的所有需求和BUG
        DemandBugInfo demandBugInfo = new DemandBugInfo();
        if (StringUtils.isNotNull(dataDemandBug)) {
            demandBugInfo.setHisVersion(dataDemandBug.getHisVersion());
            demandBugInfo.setVersion(dataDemandBug.getHisVersion());
        }
        ajax.put("demandBugInfoList", demandBugInfoService.selectDemandBugInfoList(demandBugInfo));
        return ajax;
    }

    /**
     * 导出数据和需求BUG关联关系列表
     */
    @RequiresPermissions("reportworld:datademandbug:export")
    @Log(title = "数据和需求BUG关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataDemandBug dataDemandBug) {
        List<DemandBugInfo> list = dataDemandBugService.selectDataDemandBugList(dataDemandBug);
        EasyExeclUtil.export(response, list, DemandBugInfo.class);
    }

    /**
     * 获取数据和需求BUG关联关系详细信息
     */
    @RequiresPermissions("reportworld:datademandbug:query")
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody DataDemandBug dataDemandBug) {
        return success(dataDemandBugService.getInfoDemandBugInfo(dataDemandBug));
    }

    /**
     * 新增数据和需求BUG关联关系
     */
    @RequiresPermissions("reportworld:datademandbug:add")
    @Log(title = "数据和需求BUG关联关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated DataDemandBug dataDemandBug) {
        dataDemandBugService.addDemandBugInfo(dataDemandBug);
        return success();
    }

    /**
     * 修改数据和需求BUG关联关系
     */
    @RequiresPermissions("reportworld:datademandbug:edit")
    @Log(title = "数据和需求BUG关联关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated DataDemandBug dataDemandBug) {
        dataDemandBugService.editDemandBugInfo(dataDemandBug);
        return success();
    }

    /**
     * 删除数据和需求BUG关联关系
     */
    @RequiresPermissions("reportworld:datademandbug:remove")
    @Log(title = "数据和需求BUG关联关系", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody DataDemandBug dataDemandBug) {
        dataDemandBugService.deleteDemandBugInfo(dataDemandBug);
        return success();
    }
}
